<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/login.css">
</head>
<body>
    <div class="login-container">
        <div class="login-dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span><input type="text" id="username">
            </div>
            <div class="row">
                <span>密码</span><input type="password" id="password">
            </div>
            <div class="btn">
                <button>登录</button>
            </div>
            <a href="registry.html">注册</a>
        </div>
    </div>

    <script src="./js/jquery.min.js"></script>
    <script>
        let loginBtn = document.querySelector('.login-dialog .btn button')
        loginBtn.onclick = function() {
            let username = document.querySelector('.login-dialog .row #username').value
            console.dir(username)
            let password = document.querySelector('.login-dialog .row #password').value
            $.ajax({
                method: 'post',
                url: '/user/login',
                data: {
                    username: username,
                    password: password
                },
                success: function(body) {
                    console.log(body)
                    if (body != null && body.status == 200) {
                        if (body.data == true) {
                            location.href = 'client.html'
                        }else {
                            alert(body.message)
                        }
                    }else {
                        alert(body.message)
                    }
                },
                error: function(body) {
                    alert('登录时出现错误，请联系管理员！')
                }
            });
        }
    </script>
</body>
</html>